package com.javabasic2.Shootclient;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;

import javax.swing.JPanel;

public class BackgroundImage {
	
	private Image backImg;
	private Image img;
	private BoomImage boom;
	
	private int sizeX, sizeY;
	private int x, y;
	private int velocity = 1;
	private int lifePoint = 1;
	private int scroll = 0;
	private Toolkit tk;
	public int getLifePoint() {
		return lifePoint;
	}
	public void setLifePoint(int lifePoint) {
		this.lifePoint = lifePoint;
	}

	private JPanel panel;
	private MainFrame frame;


	public BackgroundImage(Image img, MainFrame frame) {
		this.frame = frame;
		this.panel = frame.getPanel();
		init(img);

		tk = panel.getToolkit();
	}
	
	public void init(Image img) {
		
		this.img = img;
		boom = new BoomImage(frame.getBoomImage(),frame);
		scroll = 0;

		
		this.backImg = panel.createImage(new FilteredImageSource(
				img.getSource(), 
				new CropImageFilter(
					0,
					0,
					sizeX, 
					frame.getHeight())));
	}

	public int getSizeX() {
		return sizeX;
	}

	public int getSizeY() {
		return sizeY;
	}

	public void setSize(int sizeX, int sizeY) {
		this.sizeX = sizeX;
		this.sizeY = sizeY;
	}

	public int getX() {
		return sizeX;
	}

	public int getY() {
		return sizeY;
	}

	public Point getCenter() {
		return new Point(x,y);
	}

	public void draw(Graphics g) {
		g.drawImage(img, 0, scroll-4000, sizeX, sizeY, Color.WHITE, panel);
		g.drawString(sizeX + " , "+ scroll, 10, 10);
		scroll += velocity;
		if(scroll > 3200)
			scroll = 0;
		
//		this.backImg = panel.createImage(new FilteredImageSource(
//				img.getSource(), 
//				new CropImageFilter(
//					0,
//					scroll,
//					frame.getWidth(), 
//					frame.getHeight())));
	}

	public void setVelocity(int velocity) {
		this.velocity = velocity;
	}
}
